Reference
  Area\Util.txt
  Util\Audio.txt
  Util\Party.txt
  Util\CommonDialog.txt
End Reference

Procedure Main(startAt)

  Dim ac = Nothing
  
  RegisterCommonEventHandlers()
  AddAreaZone(AddZone("B1", 0, 120, 0, 127, 127, 100), 1)
  AddAreaZone(AddZone("B1s", 61, 113, 0, 66, 119, 100), 1)
  
  AddZone("Entrance", 122, 122, 0)
  
  AddZone("B1_US1", 123, 122, 0)
  RegisterEventHandler("B1_US1Enter", B1_US1_Enter)
  AddZone("Entrance1", 122, 122, 0)
  
  AddZone("B1_US2", 4, 122, 0)
  RegisterEventHandler("B1_US2Enter", B1_US2_Enter)
  AddZone("Entrance2", 5, 122, 0)
  
  AddZone("B1_B1sD", 64, 118, 0)
  
  ac = AddStaticActor("StoneWall", 64, 120, 0, [A_StoneWall], StoneWall_Contact)
  
  ac = AddActor_MTStopped("Natalie", 64, 114, 0, [A_Woman], ActorMotion.Down, Nothing)
  ac = AddActor_MTStopped("EnemyA", 64, 115, 0, [A_EnemyA], ActorMotion.Up, Nothing)

  If startAt = "Entrance1" Then
    DoInsideWarp(startAt, Direction.Left, False)
  Else
    DoInsideWarp(startAt, Direction.Right, False)
  End If
  
  ChangeBGM(Music.Cave)

  NotifyEntered()
  Idle(ProcessInput)
  NotifyExiting()

End Procedure

Procedure B1_US1_Enter()
  BeginOutsideWarp([Field], "CaveABa")
End Procedure

Procedure B1_US2_Enter()
  If TestFlag("Bamcake_1") Then
    BeginOutsideWarp([Field], "CaveABb")
  Else
    DoMsg("（この階段を登れば大陸だけど）", _
      "（まだ行かないほうがよさそうだ）")
  End If
End Procedure

Procedure StoneWall_Contact()
  Dim p_name = [TheHero].Name + "："
  Dim q_name = "アルタロスの手先："
  Dim r_name = "ナタリー："
  If TestFlag("Kaure_1") AndAlso Not TestFlag("CaveAB_1") Then
    DoMsg("（ここは何かおかしい……）")
    Sleep(500)
    DoMsg("（動かせるみたいだ！）")
    If DoYesNoMsg("本当に扉を開いてよろしいですか？") Then
      Sleep(1000)
      RemoveActor("StoneWall")
      Sleep(500)
      LetActorWalk([TheHero], Direction.Up)
      DoInsideWarp("B1_B1sD", Direction.None, True)
      LetActorWalk([TheHero], Direction.Up)
      ChangeBGM(Nothing)
      DoMsg(p_name, "あ！")
      GetActor("EnemyA").Motion = ActorMotion.Down
      DoMsg(q_name, "誰だ！")
      DoMsg(r_name, "おねがいたすけて！")
      Sleep(500)
      ChangeBGM(Music.Duel)
      DoMsg(p_name, "この妖気……おまえ人間じゃないな", _
        "その娘をどうするつもりだ？")
      DoMsg(q_name, "デロク様を復活させる儀式のため", _
        "こいつにも生け贄になってもらうのだ")
      DoMsg(p_name, "デロクだか何だか知らないが", _
        "そんなことはさせない！")
      DoMsg(q_name, "威勢がいいな", _
        "ならば　先に死ね！")
      ChangeBGM(Nothing)
      If Not DoBossBattle({[E202]}) Then
        EndOfTheWorld()
        Return
      End If
      DoMsg(q_name, "くっ　このような　小僧にやられるとは……", _
        "アルタロス様　申し訳ありません……")
      RemoveActor("EnemyA")
      Sleep(500)
      LetActorWalk([TheHero], Direction.Up)
      LetActorWalk([TheHero], Direction.Up)
      DoMsg(p_name, "ナタリーさんだね？　もう大丈夫だよ")
      DoMsg(r_name, "ありがとう……本当に　ありがとう……")
      DoMsg(p_name, "町の人は？")
      DoMsg(r_name, "みんな　もう……私だけ…………")
      DoMsg(p_name, "そうか……")
      Sleep(500)
      DoMsg(p_name, "さあ　カウレに帰ろう", _
        "君のおじいさんが待ってる")
      Sleep(1000)
      CureUsPerfectly(True)
      BeginOutsideWarp([Kaure], "NatalieRescued")
      SetFlag("CaveAB_1")
    End If
  End If
End Procedure
